package org.esky.spring.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/hello")
public class HelloController {

	@RequestMapping("/sayHello")
	public String sayHello(Model model) {
		model.addAttribute("message","Hello World!!!");
		return "hello";
	}
	
	@RequestMapping("/sayHi/{message}")
	public String sayHi(@PathVariable String message, Model model) {
		model.addAttribute("message","Hi " + message + "!!!");
		return "hello";
	}
	
	@RequestMapping(value = "/helloJson/{message}", method = RequestMethod.GET)
	public @ResponseBody Hello helloJson(@PathVariable String message){
		Hello hello = new Hello();
		hello.setMessage(message);
		return hello;
	}
	
	@RequestMapping(value = "/helloXml/{message}", method = RequestMethod.GET)
	public @ResponseBody Hi helloXml(@PathVariable String message){
		Hi hi = new Hi();
		hi.setMessage(message);
		return hi;
	}
}
